//package com.yunhe.device.repository.device;
//
//import com.yunhe.device.domain.device.DeviceTree;
//import org.springframework.data.neo4j.annotation.Query;
//import org.springframework.data.neo4j.repository.Neo4jRepository;
//import org.springframework.data.repository.query.Param;
//import org.springframework.stereotype.Repository;
//
//import java.util.List;
//
//@Repository
//public interface DeviceTreeRepository extends Neo4jRepository<DeviceTree, Long> {
//
//    /**
//     * 根据电站获得设备树形
//     * @return
//     */
//    @Query("match(s{code:{code}})-[r:HAS_DEVICE_TREE]->(t1) with r,t1 match p=(t1)-[:HAS_CHILD]->(t2) where length(p)=1 " +
//            "return ID(t1) as id,t1.code as code,t1.title as title,labels(t1)[0] as type,r.level as level,t2 as child,t1 as object")
//    List<DeviceTree> getDeviceTree(@Param("code") Long code);
//
//    @Query("start parent=node({parentId}),child=node({childId}) create(parent)-[:HAS_CHILD]->(child) " +
//            "return ID(parent) as id,parent.title as title,parent.code as code,labels(parent)[0] as type,child as child")
//    DeviceTree update(@Param("parentId") Long parentId, @Param("childId") Long childId);
//
//    @Query("match(s:Station{code:{stationCode}}),(dev{code:{devCode}}) create(n:DeviceTree)," +
//            "(dev)-[:DEVICE_TREE_NODE_OF]->(n),(s)-[:HAS_DEVICE_TREE]->(n) return n")
//    DeviceTree createDeviceTreeNode(@Param("stationCode") Long stationCode, @Param("devCode") Long devCode);
//
//    @Query("match(s:Station{code:{stationCode}}) with s match p=(t1:DeviceTree)-[:HAS_CHILD]->(t2:DeviceTree) " +
//            "where (s)-[:HAS_DEVICE_TREE]->(t1) return p")
//    Iterable<DeviceTree> findByStationCode(@Param("stationCode") Long stationCode);
//
//    @Query("start n=node({id}) match(n)-[:DEVICE_TREE_NODE_OF]->(m) return ID(m)")
//    Long findDeviceId(@Param("id") Long id);
//
//    @Query("match(dev{code:{devCode}}) with dev match(dev)-[r1:DEVICE_TREE_NODE_OF]->(n:DeviceTree)," +
//            "(s:Station)-[r2:HAS_DEVICE_TREE]->(dev) delete r1,r2")
//    void deleteRelationship(@Param("devCode") Long devCode);
//
//    @Query("match(root)-[]-(d:DeviceTree) where ID(d)={id} return ID(root) as id, root.code as code,root.title as title,labels(root)[0] as type")
//    DeviceTree findRootById(@Param("id") Long id);
//
//    @Query("start n=node({id}),m=node({deviceId}) match()-[r:DEVICE_TREE_NODE_OF]->(n) delete r create(m)-[:DEVICE_TREE_NODE_OF]->(n)")
//    void updateDevice(@Param("id") Long id, @Param("deviceId") Long deviceId);
//
//    @Query("start n=node({id}),p=node({parentId}) match()-[r:HAS_CHILD]->(n) delete r create(p)-[:HAS_CHILD]->(n)")
//    void updateParent(@Param("id") Long id, @Param("parentId") Long parentId);
//}
